<?php
namespace app\admin\service;

use function think\where;

class OrderService
{
    public function index($filter)
    {
        $order = model('order');
        
        $where = [
            
        ];        
        $join = [

        ];
         
        $field = 'a.*';


        //条件查询
        $startTime = empty($filter['start_time']) ? 0 : strtotime($filter['start_time']);
        $endTime   = empty($filter['end_time']) ? 0 : strtotime($filter['end_time']);
        if (!empty($startTime) && !empty($endTime)) {
            $where['a.create_time'] = [['>= time', $startTime], ['<= time', $endTime]];
        } else {
            if (!empty($startTime)) {
                $where['a.create_time'] = ['>= time', $startTime];
            }
            if (!empty($endTime)) {
                $where['a.create_time'] = ['<= time', $endTime];
            }
        }
        //过滤收款人消费数据代码
        $keyword = empty($filter['keyword']) ? '' : $filter['keyword'];
        if (!empty($keyword)) {
            $where['a.vip_no'] = $keyword;
        }
        $order = $order->where($where)->join($join)->alias('a')->field($field)->order('order_id','DESC')->paginate(10,false,['query'=>request()->param() ]);
        return $order;    
    }
}

